package com.george.es.service.impl;

import com.george.es.dao.ArticleMapper;
import com.george.es.model.entity.Article;
import com.george.es.model.query.ArticleQueryDto;
import com.george.es.service.IArticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author GeorgeChan
 * @since 2019-06-13
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {

    @Override
    public void addArticle(Article article) {
        this.baseMapper.insert(article);
    }

    @Override
    public void updateArticle(Article article) {
        this.baseMapper.updateById(article);
    }

    @Override
    public PageInfo<Article> findSearch(ArticleQueryDto queryDto, int page, int size) {
        PageHelper.startPage(page, size, true);
        List<Article> articleList = this.baseMapper.findArtitleByParam(queryDto);
        PageInfo<Article> articlePageInfo = new PageInfo<>(articleList);
        articlePageInfo.setList(articleList);
        return articlePageInfo;
    }
}
